package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.DeviceInformationDao;
import com.tac.pojo.mes.DeviceInformation;
import com.tac.service.mes.DeviceInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DeviceInformationServiceImpl implements DeviceInformationService {

    @Autowired
    private DeviceInformationDao deviceInformationDao;


    //查询
    public Result<PageInfo<DeviceInformation>> getList(Integer pageNum, Integer pageSize, String name, String code, String model, Date produceDateStart, Date produceDateEnd, String productBatch, String manufacturer, String deviceStatus ){
        PageHelper.startPage(pageNum,pageSize);
        List<DeviceInformation> list = deviceInformationDao.getList(name, code, model, produceDateStart, produceDateEnd, productBatch, manufacturer, deviceStatus);
        PageInfo<DeviceInformation> deviceInformationPageInfo = new PageInfo<>(list);
        return Result.success(deviceInformationPageInfo);
    }
    //添加
    public Result save(DeviceInformation deviceInformation){
        Integer integer = deviceInformationDao.save(deviceInformation);
        if(integer<=0){
            return Result.error("添加失败");
        }
        return Result.success(null);
    }
    //删除
    public Result remove(List<Integer> ids){
        Integer integer = deviceInformationDao.remove(ids);
        if(integer<=0){
            return Result.error("删除失败");
        }
        return Result.success(null);
    }
    //更新
    public Result update(DeviceInformation deviceInformation){
        Integer integer = deviceInformationDao.update(deviceInformation);
        if(integer<=0){
            return Result.error("更新失败");
        }
        return Result.success(null);
    }
}
